package com.lxmes.technology.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.technology.domain.NcProcessTec;
import com.lxmes.technology.service.INcProcessTecService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 工序工艺Controller
 * 
 * @author ruoyi
 * @date 2022-11-23
 */
@RestController
@RequestMapping("/technology/processTec")
public class NcProcessTecController extends BaseController
{
    @Autowired
    private INcProcessTecService ncProcessTecService;

    /**
     * 查询工序工艺列表
     */
    @PreAuthorize("@ss.hasPermi('technology:processTec:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcProcessTec ncProcessTec)
    {
        startPage();
        List<NcProcessTec> list = ncProcessTecService.selectNcProcessTecList(ncProcessTec);
        return getDataTable(list);
    }

    /**
     * 导出工序工艺列表
     */
    @PreAuthorize("@ss.hasPermi('technology:processTec:export')")
    @Log(title = "工序工艺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcProcessTec ncProcessTec)
    {
        List<NcProcessTec> list = ncProcessTecService.selectNcProcessTecList(ncProcessTec);
        ExcelUtil<NcProcessTec> util = new ExcelUtil<NcProcessTec>(NcProcessTec.class);
        util.exportExcel(response, list, "工序工艺数据");
    }

    /**
     * 获取工序工艺详细信息
     */
    @PreAuthorize("@ss.hasPermi('technology:processTec:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncProcessTecService.selectNcProcessTecById(id));
    }

    /**
     * 新增工序工艺
     */
    @PreAuthorize("@ss.hasPermi('technology:processTec:add')")
    @Log(title = "工序工艺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcProcessTec ncProcessTec)
    {
        return toAjax(ncProcessTecService.insertNcProcessTec(ncProcessTec));
    }

    /**
     * 修改工序工艺
     */
    @PreAuthorize("@ss.hasPermi('technology:processTec:edit')")
    @Log(title = "工序工艺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcProcessTec ncProcessTec)
    {
        return toAjax(ncProcessTecService.updateNcProcessTec(ncProcessTec));
    }

    /**
     * 删除工序工艺
     */
    @PreAuthorize("@ss.hasPermi('technology:processTec:remove')")
    @Log(title = "工序工艺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncProcessTecService.deleteNcProcessTecByIds(ids));
    }

    @Log(title = "工位管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcProcessTec> util = new ExcelUtil<>(NcProcessTec.class);
        List<NcProcessTec> tecList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncProcessTecService.imporIteminfo(tecList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<NcProcessTec> util = new ExcelUtil<NcProcessTec>(NcProcessTec.class);
        util.importTemplateExcel(response, "工位信息数据");
    }
}
